package com.icinfo.cloud.provider.punish.evideinv.controller;

import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.provider.common.dto.EvidenceInfo;
import com.icinfo.cloud.provider.punish.evideinv.dto.*;
import com.icinfo.cloud.provider.punish.evideinv.service.EvidenceInventoryService;
import com.icinfo.cloud.provider.punish.evideinv.vo.EvidencePageNewVo;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.tools.utils.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 证据库 新对接 controller
 *
 * @author Administrator
 */
@RestController
@RequestMapping("/evidenceInventoryNewContact")
public class EvidenceNewContactController {

    @Resource
    private EvidenceInventoryService evidenceInventoryService;

    /**
     * 获得按钮链接
     * @param dto
     * @return
     */
    @RequestMapping("/getButtonUrl")
    public Result getSignString(@RequestBody @Validated EvidenceButtonUrlQueryDto dto){
        return Result.success("请求成功",evidenceInventoryService.getButtonUrl(dto));
    }

    /**
     * 查询证据列表
     *
     * @return
     */
    @GetMapping("/getEvideceInfo")
    public Result<List<EvidenceInfo>> getEvideceInfo(@RequestParam String caseId){
        return Result.success(evidenceInventoryService.getCaseEvidenceInfo(caseId, false));
    }


    /**
     * app接口 查询证据数量-文书+证据
     *
     * @return
     */
    @GetMapping("/getEvideceCountForCase")
    public Result<Integer> getEvideceCountForCase(@RequestParam String caseId){
        return Result.success(evidenceInventoryService.getEvideceCountForCase(caseId));
    }

    /**
     * 查询证据库案件证据列表
     * @param dto
     * @return
     *
     */
    @PostMapping("/getList")
    public Result<PageResponse<EvidencePageNewVo>> getList(@Validated @RequestBody QueryEvidencePageDto dto){
        return Result.success("请求成功",evidenceInventoryService.getEvidencePage(dto));
    }

    /**
     *
     * 删除草稿
     * @param dto
     * @return
     *
     */
    @PostMapping("/removeDraft")
    public Result removeDraft(@Validated @RequestBody EvidenceDetailQueryDto dto){
        if (evidenceInventoryService.removeDraftByUid(dto)){
            return Result.success("请求成功");
        }else {
            return Result.error("请求失败");
        }
    }

    /**
     * 删除案件和证据
     * @param dto
     * @return
     *
     */
    @PostMapping("/removeCase")
    public Result removeCase(@Validated @RequestBody DeleteEvidenceDto dto){
        if (evidenceInventoryService.removeEvent(dto.getCaseId())){
            return Result.success("请求成功");
        }else {
            return Result.error("请求失败");
        }
    }

    /**
     * 删除单个证据（非草稿）
     * @param dto
     * @return
     *
     */
    @PostMapping("/removeEvidence")
    public Result removeEvidence(@Validated @RequestBody EvidenceDetailQueryDto dto){
        if (evidenceInventoryService.removeEvidenceByUid(dto)){
            return Result.success("请求成功");
        }else {
            return Result.error("请求失败");
        }
    }
    /**
     * 重新推送案件信息到证据库
     * @author liyafeng
     * @date 2022/7/11
      * @param dto
     * @return {@link Result}
     */
    @PostMapping("/reSaveEvent")
    public Result reSaveEvent(@Validated @RequestBody EventReSaveDto dto){
        if(StringUtils.isAllBlank(dto.getCaseId(),dto.getCaseNumber())){
            return Result.error("案件id与案件编号不能同时为空");
        }
        if (evidenceInventoryService.reSaveEvent(dto)){
            return Result.success("推送成功");
        }else {
            return Result.error("推送失败");
        }
    }

    /**
     * 保存案源事件
     * @author zhangqiang
     * @date 2022/8/18
     * @param dto
     * @return {@link Result}
     */
    @PostMapping("/saveCaseSourceEvent")
    public Result saveCaseSourceEvent(@Validated @RequestBody CaseSourceEventSaveDto dto){
        if(StringUtils.isAllBlank(dto.getCaseSourceId())){
            return Result.error("案源id不能为空");
        }
        if (evidenceInventoryService.saveCaseSourceEvent(dto)){
            return Result.success("推送成功");
        }else {
            return Result.error("推送失败");
        }
    }


    /**
     * test
     * @param
     * @return
     *
     */
    @PostMapping("/test01")
    public void test01(String caseId,String caseNo){
        evidenceInventoryService.saveEvent(caseId,caseNo);
        //evidenceInventoryService.saveAppraisalDoc();
    }


    /**
     * 描述： 获取证据详情页跳转地址
     *
     * @author: zhengqiang
     * @date: 2022/8/25
     * @param: evidenceUid
     * @param: LinkType
     * @return {@link Result< String>}
     **/
    @GetMapping("/getEvidenceLink")
    public Result<String> getEvidenceLink(@RequestParam() String evidenceUid, @RequestParam String LinkType) {
        return Result.success("获取成功", evidenceInventoryService.getEvidenceLink(evidenceUid, LinkType));
    }

    @GetMapping("/deleteEvidenceByCaseId")
    public Result<String> deleteEvidenceByCaseId(@RequestParam() String caseId) {
        evidenceInventoryService.deleteEvidenceByCaseId(caseId);
        return Result.success("成功");
    }


}
